#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+5;
ll T,n,m,L,V;
ll d[N],v[N],a[N],p[N];
template<typename T>void read(T &x){
    x=0;char c=getchar();int f=1;
    for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+(c^48);
    x*=f;
}
void solveA(){
    ll minn=0,ans=0;
    for(ll i=1;i<=m;i++) minn=max(minn,p[i]);
    for(ll i=1;i<=n;i++){
        if(v[i]>V&&d[i]<=minn) ans++;
    }
    if(ans==0) m++;
    printf("%lld %lld\n",ans,m-1);
}
void solveB(){

}
void solveC(){

}
void judge(){
    bool flagA=true,flagB=true,flagC=true;
    read(n);read(m);read(L);read(V);
    for(ll i=1;i<=n;i++){
        read(d[i]);read(v[i]);read(a[i]);
    }
    for(ll i=1;i<=m;i++) read(p[i]);
    for(ll i=1;i<=m;i++){
        if(v[i]!=0) flagA=false;
        if(v[i]<=0) flagB=false;
        if(v[i]>=0) flagC=false;
    }
    if(flagA) solveA();
    if(flagB) solveB();
    if(flagC) solveC();
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    read(T);
    while(T--) judge();
    return 0;
}
